package com.singleThread.scanner;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;


/**
 * class scan
 * @author dylan
 * 2012-9-15
 */
public class MyScanner {
	
	private ArrayList<String> pathList ;
	private HashMap<String, String> result;
	
	public MyScanner(ArrayList<String> pathList) {
		super();
		this.pathList = pathList;
		result = new HashMap<String, String>();
	}

	public HashMap<String, String> getResult() {
		return result;
	}
	
	public boolean addPath(String path) {
		return pathList.add(path);
	}
	
	public void doScan() {
		for(String path : pathList) {
			File file = new File(path);
			File[] subFiles = file.listFiles();
			for(File subFile : subFiles) {
				if(subFile.isFile()) {
					result.put(subFile.getPath(), subFile.getName());
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		ArrayList<String> pathList = new ArrayList<String>();
		Scanner scanner = new Scanner(System.in);
		String tempPath = "";
		do{
			tempPath = "";
			tempPath = scanner.nextLine();
			if(!tempPath.equals(""))
				pathList.add(tempPath);
		} while(!tempPath.equals(""));
		MyScanner sc = new MyScanner(pathList);
		sc.doScan();
		HashMap<String, String> result = sc.getResult();
		File file = new File("c:\\result.txt");
		if(!file.exists())
			file.createNewFile();
		StringBuilder sb = new StringBuilder();
		FileOutputStream out = new FileOutputStream(file,true);
		Set<String> each = result.keySet();
		for(String key : each) {
			sb.append(key);
			sb.append("\n");
			System.out.println(key);
		}
		out.write(sb.toString().getBytes());
		out.flush();
		out.close();
	}
	
}
